<template>
	<div class="musicList">
		<div class="musicTop">
			<div class="title">Discover!</div>
			<div class="more">More</div>
		</div>
		<div class="musicContent">
			<van-swipe :loop="false" :width="150" :show-indicators="false" class="my-swiper">
				<van-swipe-item v-for="item in state.goodMusicList" :key="item.id" class="oneItem">
					<router-link :to="{
						path: '/musiclistitem',
						query: { id: item.id }
					}">
						<img :src="item.picUrl" alt="" />
						<span class="playCount">
							<svg class="icon" aria-hidden="true">
								<use xlink:href="#icon-bofang"></use>
							</svg>
							<span class="playCountNumber">{{ changeCount(item.playCount) }}</span>
						</span>
						<span class="name">{{ item.name }}</span>
					</router-link>
				</van-swipe-item>
			</van-swipe>
		</div>
	</div>
</template>

<script>
import { reqDiscoverGoodMusicList } from '@/api/requests/home.js'
import { reactive, onMounted } from 'vue';
export default {
	setup() {
		const state = reactive({
			goodMusicList: []
		})

		onMounted(async () => {
			let result = await reqDiscoverGoodMusicList()
			state.goodMusicList = result.data.result
		})

		const changeCount = (num) => {
			if (num > 1000000) {
				return (num / 1000000).toFixed(1) + ' M'
			}
			if (num > 1000) {
				return (num / 1000).toFixed(1) + ' K'
			}
		}

		return { state, changeCount }
	}
}
</script>

<style lang="less">
.musicList {
	width: 100%;
	margin: 0 auto;
	height: 5rem;
	padding: 0.2rem;

	.musicTop {
		margin: 0 auto;
		padding: 0 0 0 7px;
		width: 100%;
		height: .6rem;
		display: flex;
		justify-content: space-between;
		margin-bottom: .2rem;

		.title {
			font-size: .4rem;
			font-weight: 900;
			font-family: 'Courier New', Courier, monospace;
		}

		.more {
			border: 1px solid #34D79B;
			text-align: center;
			line-height: .6rem;
			padding: 0 .2rem;
			border-radius: .4rem;
			font-family: 'Courier New', Courier, monospace;

		}
	}

	.musicContent {
		width: 100%;
		margin: 5px auto;
		height: 4rem;

		.my-swiper {
			height: 100%;

			.oneItem {
				text-align: center;
				position: relative;
				padding: 0 5px;

				// &::after {
				// 	content:'';
				// 	position: absolute;
				// 	left:50%;
				// 	bottom:0;
				// 	transform: translateX(-50%);
				// 	width:120px;
				// 	height:2px;
				// 	background-color: #34D79B;
				// }
				img {
					width: 100%;
					border-radius: 8px;
				}

				.playCount {
					display: flex;
					align-items: center;
					position: absolute;
					right: 10px;
					top: 1px;
					color: rgb(255, 255, 255);
					font-size: 12px;
				}

				.name {
					margin: 0 auto;
					color: #000000;
					font-size: 14px;
					font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif
				}
			}
		}
	}
}
</style>